home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / MISC / IFF.ZIP / IFF.TXT
Encoding:
Text File  |  1989-10-15  |  8.8 KB  |  215 lines

  1. From: carolyn@cbmvax.UUCP (Carolyn Scheppner CATS)
  2. Newsgroups: comp.graphics,comp.sys.amiga
  3. Subject: Re: IFF File Format
  4. Keywords: IFF Amiga ILBM
  5. Organization: Commodore Technology, West Chester, PA
  6.  
  7. In article <2962@watale.waterloo.edu> mdadams@surya.waterloo.edu (Mike Adams) writes:
  8. >What exactly is the format of an Amiga IFF file?
  9. >I have a number of digitized images in this format that I need to
  10. >display on a machine without IFF support.
  11.  
  12.  
  13.             Intro to Amiga IFF ILBM Files and Amiga Viewmodes
  14.             =================================================
  15.           Carolyn Scheppner - Commodore Amiga Technical Support
  16.  
  17. The IFF (Interchange File Format) for graphic images on the Amiga
  18. is called FORM ILBM (InterLeaved BitMap).  It follows a standard
  19. parsable IFF format.
  20.  
  21. Sample hex dump of beginning of an ILBM:
  22. ========================================
  23.  
  24.  Important note!  You can NOT ever depend on any particular ILBM chunk
  25.  being at any particular offset into the file!  IFF files are composed,
  26.  in their simplest form, of chunks within a FORM.  Each chunk starts
  27.  starts with a 4-letter chunkID, followed by a 32-bit length of the
  28.  rest of the chunk.  You PARSE IFF files, skipping past unneeded or
  29.  unknown chunks by seeking their length (+1 if odd length) to the
  30.  next 4-letter chunkID.
  31.  
  32. 0000: 464F524D 00016418 494C424D 424D4844    FORM..d.ILBMBMHD
  33. 0010: 00000014 01400190 00000000 06000100    .....@..........
  34. 0020: 00000A0B 01400190 43414D47 00000004    .....@..CAMG....
  35. 0030: 00000804 434D4150 00000030 001000E0    ....CMAP...0....
  36. 0040: E0E00000 20000050 30303050 50500030    .... ..P000PPP.0
  37. 0050: 90805040 70707010 60E02060 E06080D0    ..P@ppp.`. `.`..
  38. 0060: A0A0A0A0 90E0C0C0 C0D0A0E0 424F4459    ............BODY
  39. 0070: 000163AC F8000F80 148A5544 2ABDEFFF    ..c.......UD*...
  40. 0080: FFBFF800 0F7FF7FC FF04F85A 77AD5DFE    ...........Zw.].
  41. etc.
  42.  
  43.  
  44. Interpretation:
  45.  
  46.       'F O R M' length  'I L B M''B M H D'<-start of BitMapHeader chunk
  47. 0000: 464F524D 00016418 494C424D 424D4844    FORM..d.ILBMBMHD
  48.  
  49.        length  WideHigh XorgYorg PlMkCoPd <- Planes Mask Compression Pad
  50. 0010: 00000014 01400190 00000000 06000100    .....@..........
  51.  
  52.       TranAspt PagwPagh 'C A M G' length  <- start of C-AMiGa View modes chunk
  53. 0020: 00000A0B 01400190 43414D47 00000004    .....@..CAMG....
  54.  
  55.       Viewmode 'C M A P' length   R g b R <- Viewmode 800=HAM | 4=LACE 
  56. 0030: 00000804 434D4150 00000030 001000E0    ....CMAP...0....
  57.  
  58.        g b R g  b R g b  R g b R  g b R g <- Rgb's are for reg0 thru regN
  59. 0040: E0E00000 20000050 30303050 50500030    .... ..P000PPP.0
  60.  
  61.        b R g b  R g b R  g b R g  b R g b
  62. 0050: 90805040 70707010 60E02060 E06080D0    ..P@ppp.`. `.`..
  63.  
  64.        R g b R  g b R g  b R g b 'B O D Y' 
  65. 0060: A0A0A0A0 90E0C0C0 C0D0A000 424F4459    ............BODY
  66.  
  67.        length   start of body data        <- Compacted (Compression=1 above)
  68. 0070: 000163AC F8000F80 148A5544 2ABDEFFF    ..c.......UD*...
  69. 0080: FFBFF800 0F7FF7FC FF04F85A 77AD5DFE    ...........Zw.].
  70. etc.
  71.  
  72. Notes on CAMG Viewmodes:  HIRES=0x8000  LACE=0x4  HAM=0x800  HALFBRITE=0x80
  73.  
  74. ------
  75.       
  76. ILBM is a fairly simple IFF FORM.  All you really need to deal with
  77. to extract the image are the following chunks:
  78.  
  79. (Note - Also watch for AUTH Author chunks and (c) Copyright chunks
  80.  and preserve any copyright information if you rewrite the ILBM)
  81.  
  82.    BMHD - info about the size, depth, compaction method
  83.           (See interpreted hex dump above)
  84.  
  85.    CAMG - optional Amiga viewmodes chunk
  86.           Most HAM and HALFBRITE ILBMs should have this chunk.  If no
  87.           CAMG chunk is present, and image is 6 planes deep, assume
  88.           HAM and you'll probably be right.  Some Amiga viewmodes
  89.           flags are HIRES=0x8000, LACE=0x4, HAM=0x800, HALFBRITE=0x80.
  90.  
  91.    CMAP - RGB values for color registers 0 to n
  92.           (each component left justified in a byte)
  93.  
  94.    BODY - The pixel data, stored in an interleaved fashion as follows:
  95.           (each line individually compacted if BMHD Compression = 1)
  96.              plane 0 scan line 0
  97.              plane 1 scan line 0
  98.              plane 2 scan line 0
  99.              ...
  100.              plane n scan line 0
  101.              plane 0 scan line 1
  102.              plane 1 scan line 1
  103.              etc.
  104.  
  105.  
  106. Body Compression
  107. ================
  108.  
  109. The BODY contains pixel data for the image.  Width, Height, and depth
  110. (Planes) is specified in the BMHD.
  111.  
  112. If the BMHD Compression byte is 0, then the scan line data is not compressed.
  113. If Compression=1, then each scan line is individually compressed as follows:
  114.  
  115.    More than 2 bytes the same stored as BYTE code value n from  -1 to -127 
  116.      followed by byte to be repeated (-n) + 1 times.
  117.    Varied bytes stored as BYTE code n from 0 to 127 followed by n+1 bytes 
  118.      of data.
  119.    The byte code -128 is a NOP.
  120.  
  121.  
  122. Interpreting the Scan Line Data:
  123. ================================
  124.  
  125. If the ILBM is not HAM or HALFBRITE, then after parsing and uncompacting
  126. if necessary, you will have N planes of pixel data.  Color register
  127. used for each pixel is specified by looking at each pixel thru the planes.
  128. IE - if you have 5 planes, and the bit for a particular pixel is set in 
  129. planes 0 and 3:
  130.  
  131.        PLANE     4 3 2 1 0
  132.        PIXEL     0 1 0 0 1
  133.  
  134.    then that pixel uses color register binary 01001 = 9
  135.  
  136. The RGB value for each color register is stored in the CMAP chunk of the 
  137. ILBM, starting with register 0, with each register's RGB value stored as
  138. one byte of R, one byte G, and one byte of B, with each component left
  139. justified in the byte.  (ie. Amiga R, G, and B components are each stored
  140. in the high nibble of a byte)
  141.  
  142.  
  143.  
  144. BUT - if the picture is HAM or HALFBRITE, it is interpreted differently.
  145.                         ===    =========
  146.  
  147. Hopefully, if the picture is HAM or HALFBRITE, the package that saved
  148. it properly saved a CAMG chunk (look at a hex dump of your file with
  149. ascii interpretation - you will see the chunks - they all start with
  150. a 4-ascii-char chunk ID).  If the picture is 6 planes deep and has no
  151. CAMG chunk, it is probably HAM.   If you see a CAMG chunk, the "CAMG" is
  152. followed by the 32-bit chunk length, and then the 32-bit Amiga Viewmode
  153. flags.  
  154.  
  155. HAM pics will have the 0x800 bit set in CAMG chunk ViewModes.
  156. HALBRITE pics will have the 0x80 bit set.
  157.  
  158. To transport a HAM or HALFBRITE picture to another machine, you must
  159. understand how HAM and HALFBRITE work on the Amiga.
  160.  
  161. How Amiga HAM mode works:
  162. =========================
  163.  
  164.    Amiga HAM (Hold and Modify) mode lets the Amiga display all 4096 RGB
  165. values. In HAM mode, the bits in the two last planes describe an R G or
  166. B modification to the color of the previous pixel on the line to create
  167. the color of the current pixel.  So a 6-plane HAM picture has 4 planes
  168. for specifying absolute color pixels giving up to 16 absolute colors
  169. which would be specified in the ILBM CMAP chunk.  The bits in the last
  170. two planes are color modification bits which cause the Amiga, in HAM mode,
  171. to take the RGB value of the previous pixel (Hold and), substitute the 4
  172. bits in planes 0-3 for the previous color's R G or B component (Modify)
  173. and display the result for the current pixel.  The color modification bits
  174. in the last two planes are interpreted as follows:
  175.  
  176.    00 - no modification.  Use planes 0-3 as normal color register index
  177.    10 - hold previous, replacing Blue component with bits from planes 0-3 
  178.    01 - hold previous, replacing Red component with bits from planes 0-3
  179.    11 - hold previous. replacing Green component with bits from planes 0-3
  180.  
  181.  
  182. How Amiga HALFBRITE mode works:
  183. ===============================
  184.  
  185.    This one is simpler.  In HALFBRITE mode, the Amiga interprets the
  186. bit in the last plane as HALFBRITE modification.  The bits in the other
  187. planes are treated as normal color register numbers (RGB values for each
  188. color register is specified in the CMAP chunk).  If the bit in the last 
  189. plane is set (1), then that pixel is displayed at half brightness. 
  190. This can provide up to 64 absolute colors.
  191.  
  192.  
  193. Other Notes:
  194. ============
  195.  
  196.    Amiga ILBMs images must be a even number of bytes wide.  Smaller
  197. images (such as brushes) are padded to an even byte width.
  198.  
  199.    ILBMs created with Electronic Arts IBM and Amiga "DPaintII" packages
  200. are compatible (though you may have to use a '.lbm' filename extension
  201. on an IBM).  The ILBM graphic files may be transferred between the
  202. machines (or between the Amiga and IBM sides your Amiga if you have
  203. a CBM Bridgeboard card installed) and loaded into either package.
  204.  
  205.  
  206. -- 
  207. ==========================================================================
  208.   Carolyn Scheppner -- CATS  Commodore Amiga Technical Support
  209.   PHONE 215-431-9180   UUCP  ...{uunet,allegra,rutgers}!cbmvax!carolyn 
  210.  
  211.  Oh I'm a numberjack and I'm OK, I code all night and I work all day...
  212. ==========================================================================
  213.  
  214.  
  215.